package com.societyGames.codeAlong.state.codeExercise.view.menus
{
import com.societyGames.codeAlong.DonationManager;
import com.societyGames.flashForms.DialogManager;
import com.societyGames.flashForms.IDialog;
import com.societyGames.flashForms.TextButton;
import com.societyGames.flashForms.VerticalStackContainer;
import com.societyGames.flashForms.Window;
import com.societyGames.flashForms.basicSkin.BasicControls;
import com.societyGames.system.EventObject;

import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.EventDispatcher;

public class MainMenuDialog extends EventDispatcher implements IDialog
{
  private var _completeEventObject:EventObject;
  private var _showMissionSelectEventObject:EventObject; //Event

  public function MainMenuDialog()
  {
    this._completeEventObject = new EventObject(this, "COMPLETE");
    this._showMissionSelectEventObject = new EventObject(this, "SHOW_MISSION_SELECT");
    initializeInterface();
  }

  public function get showMissionSelectEventObject():EventObject //Event
  {
    return this._showMissionSelectEventObject;
  }

  private function missionSelectCallback(event:Event):void
  {
    this._showMissionSelectEventObject.dispatchEvent();
    this._completeEventObject.dispatchEvent(); //Hide ourselves for now.
  }

  private function aboutCallback(event:Event):void
  {
    var aboutDialog:AboutDialog = new AboutDialog();
    DialogManager.instance.showDialog(aboutDialog);
  }

  private function donateCallback(event:Event):void
  {
    DonationManager.showDonationPage();
  }

  private function closeCallback(event:Event):void
  {
    this._completeEventObject.dispatchEvent();
  }

  //IDialog-->
  public function get completeEventObject():EventObject
  {
    return this._completeEventObject;
  }

  public function get displayObject():DisplayObject
  {
    return this._window;
  }

  //<--IDialog

  private var _window:Window;

  private function initializeInterface():void
  {
    this._window = BasicControls.createWindow("Menu");
    this._window.width = 260;
    this._window.height = 400;

    var missionSelectButton:TextButton = BasicControls.createTextButton(missionSelectCallback);
    missionSelectButton.text = "Select Mission";
    var aboutButton:TextButton = BasicControls.createTextButton(aboutCallback);
    aboutButton.text = "Learn About";
    var donateButton:TextButton = BasicControls.createTextButton(donateCallback);
    donateButton.text = "Donate";
    var closeButton:TextButton = BasicControls.createTextButton(closeCallback);
    closeButton.text = "Close";

    missionSelectButton.width = this._window.innerWidth;
    aboutButton.width = this._window.innerWidth;
    donateButton.width = this._window.innerWidth;
    closeButton.width = this._window.innerWidth;

    var verticalStackContainer:VerticalStackContainer = new VerticalStackContainer();
    verticalStackContainer.addItem(missionSelectButton);
    verticalStackContainer.addItem(aboutButton);
    verticalStackContainer.addItem(donateButton);
    verticalStackContainer.addItem(closeButton);

    this._window.item = verticalStackContainer;
    this._window.innerHeight = verticalStackContainer.height;
  }
}
}